function ajax({url,type="GET",data={},success,error,timeout=100000}={}){
    let str=""
    for(let i in data){
        str+=`${i}=${data[i]}&&`
    }
    if(type==="GET"){
        url+="?"+str+"_x_="+Math.random()+Date.now()
    }                                                               
    const xhr=new XMLHttpRequest()
    xhr.open(type,url,true)
    xhr.onreadystatechange=function(){
        if(xhr.readyState===4 && xhr.status===200){
            success&&success(xhr.responseText)
            success=null
            error=null
        }else if(xhr.responseText===4 && xhr.status!==200){
            error&&error(xhr.status)
            success=null
            error=null
        }
    }
    if(type==="POST"){
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
        xhr.send(str)
    }else{
        xhr.send()
    }
    setTimeout(function(){
        error&&error("超时!!!")
        success=null
        error=null
    },timeout)
}
